package com.aj.http;

import android.content.Context;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.BinaryHttpResponseHandler;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.ResponseHandlerInterface;
import com.loopj.android.http.SyncHttpClient;

import cz.msebera.android.httpclient.HttpEntity;

public class HttpUtils {
	private static AsyncHttpClient asyncClient = new AsyncHttpClient(); // 实例话对象
	private static SyncHttpClient synClient = new SyncHttpClient();

	private static final int TIMEOUT_INT = 10 * 1000;

	static {
		asyncClient.setTimeout(TIMEOUT_INT); // 设置链接超时，如果不设置，默认为10s
		synClient.setTimeout(TIMEOUT_INT);
	}

	public static void asyncGet(String urlString, AsyncHttpResponseHandler res) // 用一个完整url获取一个string对象
	{
		asyncClient.get(urlString, res);
	}

	public static void asyncGet(String urlString, RequestParams params,
			AsyncHttpResponseHandler res) // url里面带参数
	{
		asyncClient.get(urlString, params, res);
	}

	public static void asyncGet(String urlString, JsonHttpResponseHandler res) // 不带参数，获取json对象或者数组
	{
		asyncClient.get(urlString, res);
	}

	public static void asyncGet(String urlString, RequestParams params,
			JsonHttpResponseHandler res) // 带参数，获取json对象或者数组
	{
		asyncClient.get(urlString, params, res);
	}

	public static void asyncGet(String uString,
			BinaryHttpResponseHandler bHandler) // 下载数据使用，会返回byte数据
	{
		asyncClient.get(uString, bHandler);
	}

	public static void asyncPost(String urlString, AsyncHttpResponseHandler res) // 用一个完整url获取一个string对象
	{
		asyncClient.post(urlString, res);
	}

	public static void asyncPost(String urlString, RequestParams params,
			AsyncHttpResponseHandler res) // url里面带参数
	{
		asyncClient.post(urlString, params, res);
	}

	public static void asyncPost(Context context, String url,
			HttpEntity entity, String applicationType,
			AsyncHttpResponseHandler res) // url里面带参数
	{
		asyncClient.post(context, url, entity, applicationType, res);
	}

	public static void asyncPost(String urlString, JsonHttpResponseHandler res) // 不带参数，获取json对象或者数组
	{
		asyncClient.post(urlString, res);
	}

	public static void asyncPost(String urlString, RequestParams params,
			JsonHttpResponseHandler res) // 带参数，获取json对象或者数组
	{
		asyncClient.post(urlString, params, res);
	}

	public static void asyncPost(String uString,
			BinaryHttpResponseHandler bHandler) // 下载数据使用，会返回byte数据
	{
		asyncClient.post(uString, bHandler);
	}

	public static void syncGet(String urlString, RequestParams params,
			ResponseHandlerInterface responseHandler) {
		synClient.get(urlString, params, responseHandler);
	}

	public static void syncGet(String urlString, ResponseHandlerInterface res) // 用一个完整url获取一个string对象
	{
		synClient.get(urlString, res);
	}

	public static void syncGet(String urlString, JsonHttpResponseHandler res) // 不带参数，获取json对象或者数组
	{
		synClient.get(urlString, res);
	}

	public static void syncGet(String urlString, RequestParams params,
			JsonHttpResponseHandler res) // 带参数，获取json对象或者数组
	{
		synClient.get(urlString, params, res);
	}

	public static void syncGet(String uString,
			BinaryHttpResponseHandler bHandler) // 下载数据使用，会返回byte数据
	{
		synClient.get(uString, bHandler);
	}

	public static void syncPost(String urlString, ResponseHandlerInterface res) // 用一个完整url获取一个string对象
	{
		synClient.post(urlString, res);
	}

	public static void syncPost(String urlString, RequestParams params,
			ResponseHandlerInterface res) // url里面带参数
	{
		synClient.post(urlString, params, res);
	}

	public static void syncPost(String urlString, JsonHttpResponseHandler res) // 不带参数，获取json对象或者数组
	{
		synClient.post(urlString, res);
	}

	public static void syncPost(String urlString, RequestParams params,
			JsonHttpResponseHandler res) // 带参数，获取json对象或者数组
	{
		synClient.post(urlString, params, res);
	}

	public static void syncPost(String uString,
			BinaryHttpResponseHandler bHandler) // 下载数据使用，会返回byte数据
	{
		synClient.post(uString, bHandler);
	}

	public static AsyncHttpClient getAsynClient() {
		return asyncClient;
	}

	public static SyncHttpClient getSyncClient() {
		return synClient;
	}
}
